﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Namespace Arwani
    Partial Class Product_6
        Inherits System.Web.UI.Page
        Protected str_Script As String = ""
        Protected strProduct_Images As String = ""

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Call setDivision_BrandName()
            If IsPostBack Then Exit Sub

            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from product where brandid=" & CInt(Request.QueryString("bid")) & " order by sortorder"

            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)

            Me.dtProducts.DataSource = dtTable
            Me.dtProducts.DataBind()
        End Sub
        Public Sub setDivision_BrandName()
            Dim arwCon As New ArwaniController
            Dim _divisionID As Integer = CInt(Request.QueryString("divid"))
            Dim _divisionTitle As String = getDivisionName(_divisionID)
            Dim strQ As String = "select * from brand where brandid=" & CInt(Request.QueryString("bid"))
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("brandname")) Then Me.lblBrandName.Text = "<a href='Default.aspx'>Home</a> / <a href='Brands.aspx?divid=" & _divisionID & "'>" & _divisionTitle & "</a> / " & dtTable.Rows(0)("brandname")
            End If
            Me.lnkBackToDivHome.Text = "Go back to " & _divisionTitle

        End Sub
        Public Function getDivisionName(ByVal _divisionID As Integer) As String
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from division where divisionid=" & _divisionID
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("divisiontitle")) Then Return dtTable.Rows(0)("divisiontitle")
            End If
            Return "N/A"
        End Function

        Public Function getImage(ByVal imgSrc As String) As String
            Dim strReturn As String = "images/main_banner.png"
            If File.Exists(Server.MapPath("Products/" & imgSrc)) Then
                strReturn = "Products/" & imgSrc
            End If
            Return strReturn
        End Function
        Protected Sub dtProducts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dtProducts.ItemDataBound
            Try
                Dim hidF As HiddenField = CType(e.Item.FindControl("hidF"), HiddenField)
                Dim lblProd As Label = CType(e.Item.FindControl("lblProd"), Label)
                Dim arwCon As New ArwaniController

                Dim strQ As String = "select pi.productimage,pi.productid  from product_images pi  where pi.productid=" & CInt(hidF.Value)
                Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
                Dim iCount As Integer = 0
                If dtTable.Rows.Count > 0 Then
                    strProduct_Images = "<div id='div_slider_" & CInt(hidF.Value) & "'>"
                    'str_Script &= "<script language='javascript'>"
                    For iCount = 0 To dtTable.Rows.Count - 1
                        strProduct_Images &= "<a href='#'> <img id='prod_" & dtTable.Rows(iCount)("productid") & "_" & iCount & "' src='" & getImage("Products", "Thumb_Four_", dtTable.Rows(iCount)("productimage")) & "' width='133' height='175'   /></a>"
                        'Products/Thumb_Double_" & dtTable.Rows(iCount)("productimage") & "', '', '', ''],"

                    Next
                    strProduct_Images &= "</div>"
                    'str_Script &= "</script>"
                    lblProd.Text = strProduct_Images
                    str_Script &= "$('#div_slider_" & CInt(hidF.Value) & "').coinslider({ effect: '', opacity: 0.7, links: false, delay: 5000, navigation: true, opacity: 0.7, width: 133, height: 175, hoverPause: false });"
                End If
                'Dim iCount As Integer = 0
                'Dim strArray As String = ""
                'For iCount = 0 To dtTable.Rows.Count - 1
                '    strArray &= "['Products/Thumb_Double_" & dtTable.Rows(iCount)("productimage") & "', '', '', ''],"
                'Next
                'If strArray <> "" Then
                '    strArray = strArray.Substring(0, strArray.Length - 1)
                '    Dim strScript As String = ""
                '    strScript = "var mygallery_" & hidF.Value & " = new simpleGallery({"
                '    strScript &= "wrapperid: 'simplegallery_" & hidF.Value & "', "
                '    strScript &= "dimensions: [195, 200], "
                '    strScript &= "imagearray: ["
                '    strScript &= strArray
                '    strScript &= "],"
                '    strScript &= "autoplay: [true, 2500, 200], "
                '    strScript &= "persist: false, "
                '    strScript &= "fadeduration: 500,"
                '    strScript &= "oninit: function () {},"
                '    strScript &= "onslide: function (curslide, i) {}"
                '    strScript &= "})"
                '    str_Script &= strScript & vbCrLf
                'End If

            Catch ex As Exception

            End Try
        End Sub
        Public Function getImage(ByVal _Folder As String, ByVal Prefix As String, ByVal imgSrc As String) As String
            Dim strReturn As String = "images/main_banner.png"
            If File.Exists(Server.MapPath(_Folder & "/" & Prefix & imgSrc)) Then
                strReturn = _Folder & "/" & Prefix & imgSrc
            End If
            Return strReturn
        End Function

        Protected Sub lnkBackToDivHome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBackToDivHome.Click
            Response.Redirect("Brands.aspx?divid=" & CInt(Request.QueryString("divid")))
        End Sub
    End Class
End Namespace